package tankGame04.tank;

import static tankGame04.tank.Bullet.BULLET_LENGTH;

/**
 * Created with IntelliJ IDEA
 * Description:
 * User:22954
 * Date:2024-03-01
 * Time:12:05
 */
@SuppressWarnings("unused")
public class Hero extends Tank {
    private Bullet bullet = null;

    public Hero(int x, int y) {
        super(x, y);
    }

    public Hero(int x, int y, int direct, int speed) {
        super(x, y, direct, speed);
    }

    public Hero(int x, int y, int direct) {
        super(x, y, direct);
    }

    @Override
    public void move(int direct, int speed) {
        super.setDirect(direct);
        switch (direct) {
            case 0:
                if (getY() > 0) setY(getY() - speed);
                break;
            case 1:
                if (getX() + TANK_SIZE / 2 * 3 <= 1000) setX(getX() + speed);
                break;
            case 2:
                if (getY() + 2 * TANK_SIZE <= 750) setY(getY() + speed);
                break;
            case 3:
                if (getX() > 0) setX(getX() - speed);
                break;
        }
    }

    @Override
    public void shot() {
        if (bullet == null || !bullet.isState()) {
            int bx = 0, by = 0;
            by = switch (getDirect()) {
                case 0 -> {
                    bx = getX() + TANK_SIZE / 2 - 1;
                    yield getY() - BULLET_LENGTH;
                }
                case 1 -> {
                    bx = getX() + TANK_SIZE;
                    yield getY() + TANK_SIZE / 2 - 1;
                }
                case 2 -> {
                    bx = getX() + TANK_SIZE / 2 - 1;
                    yield getY() + TANK_SIZE;
                }
                case 3 -> {
                    bx = getX() - BULLET_LENGTH;
                    yield getY() + TANK_SIZE / 2 - 1;
                }
                default -> by;
            };
            bullet = new Bullet(bx, by, getDirect(), true);
            new Thread(bullet).start();
        }
    }

    public Bullet getBullet() {
        return bullet;
    }

}
